from ...utils.workflow_manager import FuncJobModel
from ...zlgcan.zlgcan import *
from ...zuds.zuds import *
# from ...utils.workflow_manager import FuncJobModel

# from .uds_manual_main_window import UdsManualWindow
from ...globals import GLOBAL_MASTER_UI, GLOBAL_UDS_SERVE_FUNC_LIB, UdsManualWindow


class Uds_UI_Tester(Zuds_Tester_Base):
    def __init__(self, modelWin: UdsManualWindow, channel=0, *args, **kwargs):
        super().__init__(channel)

        # 关联modelWin
        self.modelWin = modelWin


class UI_WorkFlow(FuncJobModel):
    def __init__(self, tester: Uds_UI_Tester, masterUI):
        super().__init__()
        # 将主界面实例传递进来
        self.TESTER = tester
        self.masterUI = masterUI


def init_masterUI():

    zcanlib = GLOBAL_ZCANLIB
    device_handle = GLOBAL_ZUDS_TESTER.device_handle
    masterUI = GLOBAL_MASTER_UI
    tester = Uds_UI_Tester(masterUI)

    masterUI.set_tester(tester=tester)
    masterUI.set_zcanlib(zcanlib=zcanlib, device_handle=device_handle)

    # 配置GLOBAL_UDS_SERVE_FUNC_LIB的FUNCJOB
    funcjob = UI_WorkFlow(tester=tester, masterUI=masterUI)
    GLOBAL_UDS_SERVE_FUNC_LIB.set_funcjob(funcjob=funcjob)

    return masterUI


def uds_manual():
    ui = init_masterUI()
    ui.mainloop()


if __name__ == "__main__":
    demo = UdsManualWindow()
    demo.mainloop()
